<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html; charset=utf-8" %>
<%@page import="dataBase.Business"%>
<%@page import="controller.Controller"%>
<%@page import="dataBase.Order"%>
<%@page import="dataBase.Status"%>
<%@page import="com.google.appengine.api.datastore.Key"%>
<%@page import="java.util.List"%>
<%@page import="language.LangFactory"%>
<%@page import="language.LangIntrf"%>
<%
	LangFactory langFactory= new LangFactory();
	String langName = request.getParameter("lang");

	LangIntrf lang =null;
	if(langName!=null){
		lang = langFactory.getLang(request.getParameter("lang"));
		session.setAttribute("lang",langName);
	}
	else
		lang = langFactory.getLang((String)session.getAttribute("lang"));
	String langSign = lang.getLang();
	
	
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="js/jquery-1.6.1.min.js"></script>
<script type="text/javascript" src="js/jquery.easing.1.3.js"></script>
<script type="text/javascript" src="js/jquery.zaccordion.min.js"></script>
<link href="showOrder.css" rel="stylesheet" type="text/css" />

<%
	String orderNum = request.getParameter("orderNum");
	String bizName = request.getParameter("bizName");
	String phone = request.getParameter("phone");
	Controller controller = Controller.getInstance();
	Business business=null;
	Order order=null;
	boolean orderExist = false;
	String currentStatus="";
	List<String> statusList = null;
	int statusIndex = 0;
	
	if(orderNum!=null && bizName!=null && phone!=null && !orderNum.equals("") && !bizName.equals("")&& !phone.equals("")){
		phone = phone.replace("-","");
		business = controller.getBiz(bizName);
		System.out.println("*********************************");
		System.out.println(bizName);
		//statusList = controller.getStatusesOfBiz(bizName);
		System.out.println("asd "+orderNum);
		System.out.println("asd2 "+Integer.parseInt(orderNum));
		order = controller.getOrder(Integer.parseInt(orderNum),bizName);
		
		if(order!=null){			
			orderExist=true;	
			statusList = order.getStatusNamesList();
			currentStatus = controller.getCurrentStatusOfOrder(order);
			
			for(String s : statusList){
				if(s.equals(currentStatus))
					break;
				statusIndex++;
			}
		}
	}

	if(orderExist && !order.getPhoneNumber().getNumber().equals(phone))
		orderExist = false;
	int width =0;
	if(orderExist)
		width =200+40*(statusList.size()-1);
%>
<style type="text/css">
#my {
	width: <%=width%>px; 
}
</style>
<script type="text/javascript">
	$(document).ready(function() {
		$("#example1").zAccordion({
			timeout: 2000,
			slideWidth: 200,
			width: <%=width%>,
			height: 120,
			auto: false,
			startingSlide: <%=statusIndex%>, 
			trigger: "mouseover",
			animationComplete: function () {
				if($(this).index()<<%=statusIndex%>){
					$("#example1").delay(5000).zAccordion("trigger", <%=statusIndex+1%>);
				}
				else{
					$("#example1").delay(5000).zAccordion("trigger", <%=statusIndex%>);
				}
			}
		});
	});
	
</script>

</head>

<body style="text-align: <%=lang.getAlign()%>;">

<%if(orderExist){ %>
	<%if(lang.getAlign().equals("left")){ %>
		<%=lang.getORDER_NUBER_LABEL()%> <%=order.getOrderNum() %><br/>
		<%=lang.getCREAT_DATE_LABEL()%> <%=order.getStartTimeFormat() %><br/>
	<%}else{ %>
		<%=order.getOrderNum()%><%=lang.getORDER_NUBER_LABEL() %> <br/>
		<%=order.getStartTimeFormat()%><%=lang.getCREAT_DATE_LABEL() %><br/>	
	<%} %>

<div id="my" style="text-align: left;">
			<ul id="example1">
			<%
				for(int i=0;i<statusIndex;i++){
			%>
				<li class="over">
					<div class="statusContent"><%=statusList.get(i) %></div>
                    <div class="v" style="color:#0F3;!important"><img src="images/v.png" width="30" height="30"/> <p>Done!</p></div>
				</li>
			<%  }
				
			%>
				<li class="current">
					<div class="statusContent"><%=currentStatus %></div>
					<div class="v"><img src="images/wait.png" width="30" height="30"/><p>Pending</p></div>
				</li>
			<%
				for(int i=statusIndex+1;i<statusList.size();i++){
			%>
				<li class="next">
					<div class="statusContent"><%=statusList.get(i) %></div>
					<div class="v"><img src="images/next.png" width="30" height="30"/><p>Next</p></div>
				</li>
			<%  }
			%>
				
           
			</ul>
			</div><br/>
			<% if ((!business.getWebsite().equals("")) && (!business.getWebsite().equals("http://"))) {%>
				<%if(lang.getAlign().equals("left")){ %>
					<%=lang.getBUSINESS_WEBSITE_LABEL() %> <a href="<%=business.getWebsite() %>" target="<%=business.getBizName()%>"><%= business.getWebsite() %></a><br/>
				<%}else{ %>
					<a href="<%=business.getWebsite() %>" target="<%=business.getBizName()%>"><%= business.getWebsite() %></a><%=lang.getBUSINESS_WEBSITE_LABEL() %> <br/>
				<%} %>
			<%} %>
			<%if (business.getLogoPic()!=null){ %>
				<img src="/showImage?imageKey=<%=business.getUserName() %>" width="100" /> <br/>
			<% }%>
<%	}
else{
%>
<center>
<b><%=lang.getSORRY_LABEL() %></b><br/><br/>
</center>
<%} %>
			
			
</body>
</html>
